#ifndef CAMERA6467_VFR_H
#define CAMERA6467_VFR_H

#include "cameraModule/BaseCamera.h"
#include"cameraModule/Camera6467_plate.h"
#include"cameraModule/CameraResult.h"
#include "ResultListManager.h"

#include "common/commonDefFun.h"
#include "cameraModule/ThreadSafeList.h"
#include "Plugins/customFuncHelper/cDequeLikeUnorderSet.h"


//#include<thread>

namespace libcvos_vfr
{

	class Camera6467_VFR :
		public BaseCamera
	{
	public:
		Camera6467_VFR();
		virtual ~Camera6467_VFR();

	private:
		void ReadConfig();
		void AnalysisAppendXML(CameraResult* CamResult);

		int AnalysisBusVehAxleType(int WheelCount, const char* plateNumber);

		//************************************
		// Method:        CheckIfSuperLength
		// Describe:       查看当前车是否为超长车，如果是，则后续的逻辑需清理车型队列
		// FullName:      Camera6467_VFR::CheckIfSuperLength
		// Access:          private 
		// Returns:        bool
		// Returns Describe:
		// Parameter:    CameraResult * CamResult
		//************************************
		bool CheckIfSuperLength(CameraResult* CamResult);

		//************************************
		// Method:        CheckIfBackUpVehicle
		// Describe:        检查该结果是否为倒车结果
		// FullName:      Camera6467_VFR::CheckIfBackUpVehicle
		// Access:          private 
		// Returns:        bool
		// Returns Describe:
		// Parameter:    CameraResult * CamResult
		//************************************
		bool CheckIfBackUpVehicle(CameraResult* CamResult);

	public:
        bool SendFrontImageByCallback(CameraResult* CamResult, int index);
        bool SendExtraResultByCallback(CameraResult* CamResult, int vlpExtraType, int index);

		void SetMsgHandleAngMsg(void* handle, int msg);
		void NotifyFrontResult();

		void SetExtraMsgNotify(void* handle, int msg);
		void NotifyExtraData();

		bool OpenPlateCamera(const char* ipAddress);
        ResultListManager::Result_Type GetFrontResult();
		CameraResult *GetLastResult();
        ResultListManager::Result_Type  GetResultByPlateNo(const char* plateNo, bool& bMatch);
        ResultListManager::Result_Type  GetFrontResultByPosition(std::string::size_type position);
        ResultListManager::Result_Type createCaptureResult();
        ResultListManager::Result_Type getResultByListNo(const char* listNo);
        ResultListManager::Result_Type getResultByCarid(unsigned long carid);

		std::string GetAllVehTypeList();
		void DeleteFrontResult(const char* plateNo);
		void ClearALLResult();
		size_t GetResultListSize();

		bool checkIfHasThreePic(CameraResult* result);

		std::string getTempVideoFileName();
		void setTempVideoFileName(const char* fileName);

		bool GetIfOverlay();

		bool getFirstExtraInfoID(unsigned long& carID);

        void sendStatusBycallback(int iStatus);
	public:
		virtual int DeviceJPEGStream(
			unsigned char* pbImageData,
			unsigned long dwImageDataLen,
			unsigned long dwImageType,
			const char* szImageExtInfo);

		virtual int OnHvResultILLEGALVideo(
			unsigned long dwCarID,
			unsigned long dwVideoType,
			unsigned long dwVideoWidth,
			unsigned long dwVideoHeight,
			unsigned long long dw64TimeMS,
			unsigned char *pbVideoData,
			unsigned long dwVideoDataLen,
			const char *szVideoExtInfo);

        virtual int OnHvResult_callback(
                unsigned long dwResultFlag,
                unsigned long dwResultType,
                unsigned long dwCarID,
                const char *pcPlateNo,
                const char *pcAppendInfo,
                unsigned long long dw64TimeMS,
                CImageInfo   Plate,
                CImageInfo   PlateBin,
                CImageInfo   BestSnapshot,
                CImageInfo   LastSnapshot,
                CImageInfo   BeginCapture,
                CImageInfo   BestCapture,
                CImageInfo   LastCapture
                );

		virtual void CheckStatus();

        virtual void SendResult();
	private:
		unsigned long m_dwLastCarID;

		int m_iSuperLenth;

		int m_iResultMsg;
		int m_iExtraMsg;

		bool m_bOverlay;
        bool m_bEnableFilter;
        bool m_bFilterNoLisence;

		CameraIMG m_Small_IMG_Temp;
        CameraIMG m_Binary_IMG_Temp;
		//CameraIMG m_CIMG_StreamJPEG;

		//std::shared_ptr<Camera6467_plate> m_Camera_Plate;
		Camera6467_plate* m_Camera_Plate;

		CameraResult* m_pResult;
		CameraResult* m_pBufferResult;
		ResultListManager m_resultList;
        //ResultListManager m_VfrCallbackResultList;

		TemplateThreadSafeList<unsigned long> m_lsExtraInfoIdList;

		void* m_pMsgHandle;
        void* m_pMsgExtraData;

		std::list<std::string> m_lsVideoName;
		std::string m_strTempVideoFileName;

	public:
		cDequeLikeUnorderSet m_carIDList;

	private:
		struct ReceiveTimeFlag
		{
			unsigned long _carID;
			unsigned long long _dw64Time;

			ReceiveTimeFlag(unsigned long carID, unsigned long long dw64Time) :
				_carID(carID),
				_dw64Time(dw64Time)
			{
			}
		};

		std::list<std::shared_ptr<ReceiveTimeFlag>> m_lsReceiveTime;

		bool GetReceiveTimeByCarID(unsigned long carID, unsigned long long& dwTime);
		void SetReceiveTimeByCarID(unsigned long carID, unsigned long long dwTime);
	};
}

#endif
